<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<h:body>

	<ui:composition template="/commonLayout.xhtml">
		<ui:define name="content">
			<p:dataTable id="messageTable" var="m"
				value="#{messageList.messageList}" paginator="true" rows="10"
				paginatorPosition="bottom"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">

				<p:ajax event="rowToggle" listener="#{messageList.mettreALu}"
					update=":messageTable" />
				<p:column style="width:4%">
					<p:rowToggler />
				</p:column>

				<p:column>
					<f:facet name="header">  
                    Emetteur  
            	</f:facet>
					<h:outputText value="#{messageList.recupUser(m.idEmetteur)}"
						rendered="#{m.lu}">
					</h:outputText>
					<h:outputText value="#{messageList.recupUser(m.idEmetteur)}"
						style="font-weight:bold;" rendered="#{m.lu == false}" />
				</p:column>
				<p:column style="width:46%;">
					<f:facet name="header">  
                    Objet  
	            </f:facet>
					<h:outputText value="#{m.titre}" rendered="#{m.lu}" />
					<h:outputText value="#{m.titre}" style="font-weight:bold;"
						rendered="#{m.lu == false}" />
				</p:column>


				<p:column>
					<f:facet name="header">  
                    Action  
            		</f:facet>
					<h:commandButton id="showDialogButton" styleClass="btn"
						image="./resources/images/sendMail.png" onclick="dlg.show()"
						style="margin-right:5px;">

					</h:commandButton>
					<h:commandButton id="showDeleteButton" styleClass="btn"
						image="./resources/images/delete.png"
						onclick="fenetreSuppr.show()">

					</h:commandButton>

				</p:column>
				<p:rowExpansion>
					<div class="divMessagerie">
						<h:outputText value="#{m.texte}" escape="false"></h:outputText>
					</div>
				</p:rowExpansion>
			</p:dataTable>

			<p:dialog
				header="Envoi d'un message à #{messageList.recupUser(m.idEmetteur)}"
				widgetVar="dlg" resizable="false">
				<div class="formArticle well">
					<h:form>
						<fieldset>
							<table>
								<tr>
									<td><h5>Le message</h5></td>
								</tr>
								<tr>
									<td><h:inputText id="titre" style="width:97%" name="titre"
											value="#{messageList.article.titre}" /> <p:watermark
											value="Titre.." for="titre"></p:watermark></td>
								</tr>
								<tr>
									<td><h:inputTextarea value="#{messageList.article.texte}"
											id="texte" /></td>
								</tr>
								<tr>
									<td><h:commandButton styleClass="btn btn-info" id="submit"
											value="Envoyer un message" action="#{messageList.envoyerMessage(m.idEmetteur)}"
											onclick="alert(tinyMCE.get('elm1').getContent());return false;">
										</h:commandButton></td>
								</tr>

							</table>
						</fieldset>

					</h:form>
				</div>
			</p:dialog>

			<p:dialog header="Etes-vous sur de vouloir supprimer le message ?"
				widgetVar="fenetreSuppr" resizable="false">
				<div class="formArticle well">
					<h:form>
						<fieldset>
							<table>
								<tr>
									<td><h:commandButton styleClass="btn btn-info"
											id="submitSuppr" value="Oui"
											action="#{messageList.supprimer(m.idArticle)}">
										</h:commandButton></td>
									<td><h:commandButton styleClass="btn btn-info"
											id="supprMessage" value="Non" onclick="fenetreSuprr.hide()">
										</h:commandButton></td>
								</tr>
							</table>
						</fieldset>

					</h:form>
				</div>
			</p:dialog>

		</ui:define>
	</ui:composition>

</h:body>
</html>